﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xunit;
using M3G;

namespace MyTestProject {
    
    public class TestAppearance {
        [Fact]
        public void TestConstructor () {
            var app = new Appearance ();

            Assert.Equal (0, app.Layer);
            Assert.Equal (null, app.Fog);
            Assert.Equal (null, app.Material);
            Assert.Equal (null, app.PointSpriteMode);
            Assert.Equal (null, app.Texture[0]);
            Assert.Equal (null, app.Texture[1]);
        }

        [Fact]
        public void TestSetMaterial () {
            var app = new Appearance ();
            var mat = new Material ();
            app.SetMaterial (mat);

            Assert.Equal (mat, app.Material);
        }

        [Fact]
        public void TestSetFog () {
            var app = new Appearance ();
            var fog = new Fog ();
            app.SetFog (fog);
            
            Assert.Equal (fog, app.Fog);
        }


        [Fact]
        public void TestSetPointSpriteMode () {
            var app = new Appearance ();
            var psmode = new PointSpriteMode ();
            app.SetPointSpriteMode (psmode);

            Assert.Equal (psmode, app.PointSpriteMode);
        }

        [Fact]
        public void TestSetTexture () {
            var app = new Appearance ();
            var img = new Image2D (Image2D.RGBA, 16, 16);
            var tex0 = new Texture2D (img);
            var tex1 = new Texture2D (img);
            app.SetTexture (0, tex0);
            app.SetTexture (1, tex1);

            Assert.Equal (tex0, app.Texture[0]);
            Assert.Equal (tex1, app.Texture[1]);
        }

        [Fact]
        public void TestReferences () {
            var app = new Appearance ();
            var mat = new Material ();
            var fog = new Fog ();
            var psmode = new PointSpriteMode ();
            var img = new Image2D (Image2D.RGBA, 16, 16);
            var tex0 = new Texture2D (img);
            var tex1 = new Texture2D (img);
            app.SetMaterial (mat);
            app.SetFog (fog);
            app.SetPointSpriteMode (psmode);
            app.SetTexture (0, tex0);
            app.SetTexture (1, tex1);
            
            var refs = app.References;

            Assert.Equal (5, refs.Length);
            Assert.Equal (mat, refs[0]);
            Assert.Equal (fog, refs[1]);
            Assert.Equal (psmode, refs[2]);
            Assert.Equal (tex0, refs[3]);
            Assert.Equal (tex1, refs[4]);
        }

        [Fact]
        public void TestDuplicate () {
            var app = new Appearance ();
            var mat = new Material ();
            var fog = new Fog ();
            var psmode = new PointSpriteMode ();
            var img = new Image2D (Image2D.RGBA, 16, 16);
            var tex0 = new Texture2D (img);
            var tex1 = new Texture2D (img);
            app.SetMaterial (mat);
            app.SetFog (fog);
            app.SetPointSpriteMode (psmode);
            app.SetTexture (0, tex0);
            app.SetTexture (1, tex1);
            app.UserID = 100;
            
            var dup = (Appearance)app.Duplicate();

            Assert.Equal (app.Material, dup.Material);
            Assert.Equal (app.Fog, dup.Fog);
            Assert.Equal (app.PolygonMode, dup.PolygonMode);
            Assert.Equal (app.Texture[0], app.Texture[0]);
            Assert.Equal (app.Texture[1], app.Texture[1]);
            Assert.Equal (app.UserID, dup.UserID);
        }
    }
}
